//
//  HomeViewController.m
//  GentlemanAnime
//
//  Created by dlios on 15-6-29.
//  Copyright (c) 2015年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "HomeViewController.h"
#import "AppDelegate.h"
#import "DownloadViewController.h"
#import "HomeTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "LeftCollectionViewCell.h"
#import "RightCollectionViewCell.h"
#import "DownloadSingletonTool.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@interface HomeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NSArray *sandBox = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *sandBoxPath = sandBox[0];
    NSString *canSeeBoxPath = [sandBoxPath stringByAppendingPathComponent:@"canSee.txt"];
    NSString *str = [NSString stringWithContentsOfFile:canSeeBoxPath encoding:NSUTF8StringEncoding error:nil];
    [DownloadSingleton shareDownloadSingleton].canSee = [str integerValue];
    
    NSString *collcetCountBoxPath = [sandBoxPath stringByAppendingPathComponent:@"collcetCount.txt"];
    NSString *collcetCountStr = [NSString stringWithContentsOfFile:collcetCountBoxPath encoding:NSUTF8StringEncoding error:nil];
    [DownloadSingleton shareDownloadSingleton].collcetCount = [collcetCountStr integerValue];
   
    
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
    imageview.image = [UIImage imageNamed:@"leftbackiamge"];
    [self.view addSubview:imageview];

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(WIDTH - 70, HEIGHT);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) collectionViewLayout:flowLayout];
    [self.view addSubview:self.collectionView];
    self.collectionView.pagingEnabled = YES;
    self.collectionView.scrollEnabled = NO;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    [_collectionView release];
    [flowLayout release];
    
    // 注册
    [self.collectionView registerClass:[LeftCollectionViewCell class] forCellWithReuseIdentifier:@"leftReuse"];
    [self.collectionView registerClass:[RightCollectionViewCell class] forCellWithReuseIdentifier:@"rightReuse"];
   
}

#pragma mark collectionView的协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        [DownloadSingleton shareDownloadSingleton].leftIndexPath = indexPath;
        LeftCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"leftReuse" forIndexPath:indexPath];
        return cell;
    } else {
        RightCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"rightReuse" forIndexPath:indexPath];
        return cell;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
